package com.example.demo;

import com.example.demo.db2.User;
import com.example.demo.db2.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;

@SpringBootApplication
public class DemoApplication implements CommandLineRunner {

	@Autowired
	UserRepository userRepository;

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		List users = userRepository.findAll();
		if (users.size() < 1) {
			User user = new User();
			user.name = "yang";
			userRepository.save(user);
			users = userRepository.findAll();
		}
		System.out.println(users);
	}
}
